package cn.kgc.crowdfundingadminspringboot.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 项目名：crowd-funding-admin-springboot2
 * 创建人：Junyizm
 * 创建时间：2020/2/21-17:42
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResultEntity<T> {
    private String result;
    private String message;
    private T data;

    public static final String SUCCESS = "SUCCESS";
    public static final String FAILED = "FAILED";
    public static final String NO_MESSAGE = "NO_MESSAGE";
    public static final String NO_DATA = "NO_DATA";

    // 方便返回成功结果（不携带查询结果情况）
    public static ResultEntity<String> successWithoutData() {
        return new ResultEntity<String>(SUCCESS, NO_MESSAGE, NO_DATA);
    }

    // 方便返回成功结果（携带查询结果情况）
    public static <T> ResultEntity<T> successWithoutData(T data) {
        return new ResultEntity<T>(SUCCESS, NO_MESSAGE, data);
    }

    // 方便返回失败结果
    public static ResultEntity<String> failed(String message) {
        return new ResultEntity<String>(FAILED, message, NO_DATA);
    }

    // 方便返回失败结果
    public static <E> ResultEntity<E> failed(E data, String message) {
        return new ResultEntity<E>(FAILED, message, data);
    }

}
